package com.wms.controller;

import com.wms.bean.PageBean;
import com.wms.bean.ResultBean;
import com.wms.core.R;
import com.wms.dto.PurchaseDto;
import com.wms.entity.Purchase2;
import com.wms.service.PurchaseService2;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
@Api(tags = "csy采购单")
@Slf4j
public class PurchaseController2 {
    @Autowired
    PurchaseService2 purchaseService2;

    @ApiOperation(value = "获取采购单列表（多条件查询、分页）")
    @PostMapping("/purchase/list")
    public ResultBean getList(@RequestBody PurchaseDto purchaseDto){
        PageBean pageBean=purchaseService2.getAll(purchaseDto);
        return R.success("获取采购单列表",pageBean);
    }

    @ApiOperation(value = "获取采购单详情")
    @GetMapping("/purchase/getById")
    public ResultBean getDetailById(@RequestParam(required = true) int id){
        Purchase2 purchase2=purchaseService2.getById(id);
        return R.success("采购单详情",purchase2);
    }
    @ApiOperation(value = "保存采购单")
    @PostMapping("/purchase/save")
    public ResultBean savePurchase(@RequestBody Purchase2 purchase2){
        int rs=purchaseService2.save(purchase2);
        return rs==1?R.success("保存成功"):R.fail("保存失败");
    }
}
